package calorie.com.calorie.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lxh.baselibray.base.XActivity;
import com.lxh.baselibray.dialog.AlertDialog;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.SizeUtils;

import butterknife.BindView;
import butterknife.OnClick;
import calorie.com.calorie.R;
import calorie.com.calorie.contact.PersonalInfomationConstant;
import calorie.com.calorie.util.StaticValue;

/**
 * 个人信息
 */
public class PersonalInfomationActivity extends XActivity {
    @BindView(R.id.tv_nick_name_value)
    TextView tvNickNameValue;
    @BindView(R.id.tv_sex_value)
    TextView tvSexValue;
    @BindView(R.id.tv_wallet_address)
    TextView tv_wallet_address;

    @BindView(R.id.tv_receive_address)
    TextView tv_receive_address;

    @Override
    public void initData(Bundle savedInstanceState) {

        if (!ObjectUtils.isEmpty(StaticValue.user)) {
            tvNickNameValue.setText(StaticValue.user.getNickName());
            tvSexValue.setText(StaticValue.user.getSex());
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData(null);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_personal_infomation;
    }


    @OnClick({R.id.tv_nick_name, R.id.tv_sex, R.id.tv_wallet_address, R.id.tv_receive_address})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_nick_name:
                gotoModifyMsg(1);
                break;
            case R.id.tv_sex:
                showTypeDialog();
                break;
            case R.id.tv_wallet_address:
                gotoModifyMsg(2);
                break;
            case R.id.tv_receive_address:
                gotoModifyMsg(3);
                break;
        }
    }

    private void gotoModifyMsg(int from) {
        Intent intent = new Intent(context, ModifyPersonMsgActivity.class);
        intent.putExtra(ModifyPersonMsgActivity.FROM, from);
        startActivity(intent);
    }

    AlertDialog typeDialog = null;

    private void showTypeDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .addDefaultAnimation()
                .setCancelable(true)
                .setContentView(R.layout.dialog_type_select)
                .fromBottom(true)
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(context, 130))
                .setOnClickListener(R.id.tv_one, v -> {
                    tvSexValue.setText("男");
                    new PersonalInfomationConstant.PersonalInfomationPresent().updateSex("男", StaticValue.user.getId());
                    typeDialog.dismiss();
                }).setOnClickListener(R.id.tv_two, v -> {
                    tvSexValue.setText("女");
                    new PersonalInfomationConstant.PersonalInfomationPresent().updateSex("女", StaticValue.user.getId());
                    typeDialog.dismiss();
                }).setOnClickListener(R.id.tv_select_cancel, v -> typeDialog.dismiss());
        typeDialog = builder.create();
        typeDialog.show();
    }


}
